package com.fangcun.controller.api.old.agent.order;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fangcun.bean.api.agent.order.request.AgentOrderRequest;
import com.fangcun.bean.api.agent.order.request.ConfirmProiceRequest;
import com.fangcun.bean.sys.PageBean;
import com.fangcun.bean.sys.ResponseMsg;
import com.fangcun.common.canstant.ErrCode;
import com.fangcun.common.exception.ProAffairException;
import com.fangcun.common.exception.ProException;
import com.fangcun.common.util.PublicMethod;
import com.fangcun.common.util.apiversion.ApiVersion;
import com.fangcun.common.util.base.BaseController;
import com.fangcun.entity.AgentOrder;
import com.fangcun.service.api.AgentOrderService;

@RestController
@RequestMapping("/api/{version}/auth/agent/order")
public class AgentOrderController extends BaseController {
	private static Logger LOG = LoggerFactory.getLogger(AgentOrderController.class);
	
	@Autowired
	private AgentOrderService agentOrderService;
	/**订单列表**/
	@ApiVersion(1.0)
	@RequestMapping("list")
	private ResponseMsg orderList(@RequestBody PageBean<AgentOrderRequest> request) {
		ResponseMsg msg =ResponseMsg.returnBeanBuild();
		try {
			msg.setData(agentOrderService.orderList(request));
		} catch (ProException e) {
			LOG.error("-查看成交订单 出错->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("-查看成交订单 异常->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
	/**订单管理展示**/
	@ApiVersion(1.0)
	@RequestMapping("admin/list")
	private ResponseMsg list(@RequestBody PageBean<AgentOrder> request) {
		ResponseMsg msg =ResponseMsg.returnBeanBuild();
		try {
			msg.setData(agentOrderService.list(request));
		} catch (ProException e) {
			LOG.error("-代理订单管理出错->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("-代理订单管理异常->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
	/**确认收款**/
	@ApiVersion(1.0)
	@RequestMapping("update")
	private ResponseMsg update(@RequestBody ConfirmProiceRequest request) {
		ResponseMsg msg = new ResponseMsg();
		try {
			agentOrderService.confirmProice(request);
		} catch (ProAffairException e) {
			LOG.error("-代理订单修改出错->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("-代理订单修改异常->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
}
